import React, {Component} from 'react';
import NewIncreased from '../../../../../public/components/NewIncreased'
import FormView from './formView'
class AddNew extends Component{
    constructor(props) {
        super(props);
        this.state = {
            setModalVisible: false,
            isInterrupt: true
        }
    }
    // 设置新增弹窗显示隐藏
    setNewIncreasedDis (setModalVisible) {
        this.setState({
            setModalVisible 
        })
    }
    // 下一步方法
    nextHandle (selectData) {
       this.refs.addFormView.nextHandle(selectData)
    }
    // 完成方法 调用新增保存接口
    doneHandle () {
        this.refs.addFormView.doneHandle()
    }
    onClose () {
        this.refs.addFormView.onClose()
    }
    // 上一步的回调
    prevHandle () {
        this.refs.addFormView.prevHandle()
    }
    // 调用新增组件的下一步方法
    nextHandleFn () {
        this.setState({
            isInterrupt: false
        }, function () {
            this.refs.newIncreased.nextHandleFn()
        })
    }
    // 调用新增组件的上一步方法
    prevHandleFn () {
        // this.setState({
        //     isInterrupt: true
        // }, function () {
            this.refs.newIncreased.prevHandleFn()
        // })
    }
    setIsInterrupt (isInterrupt) {
        this.setState({
            isInterrupt
        })
    }
    // 提示选择续签方式
    selectExtendStyle () {
        this.refs.addFormView.selectExtendStyle()
    }
    setRecord (record){
        this.props.setRecord && this.props.setRecord(record);
    }
    render () {
        let props = this.props;
        return (
            <div className="addNew">
                {
                    this.state.setModalVisible ? 
                    <NewIncreased 
                        setModalVisible={this.state.setModalVisible}
                        fntype = {'apply'}
                        ref="newIncreased"
                        prevHandle={this.prevHandle.bind(this)}
                        {...props}
                        nextHandle={this.nextHandle.bind(this)}
                        doneHandle={this.doneHandle.bind(this)}
                        isInterrupt={this.state.isInterrupt}
                        selectExtendStyle={this.selectExtendStyle.bind(this)}
                        onClose={this.onClose.bind(this)}> 
                            <FormView 
                            setIsInterrupt={this.setIsInterrupt.bind(this)}
                            prevHandleFn={this.prevHandleFn.bind(this)}
                            ref="addFormView" 
                            isExtendAdd={true} 
                            setNewIncreasedDis={this.setNewIncreasedDis.bind(this)} 
                            setRecord={this.setRecord.bind(this)}
                            {...props} 
                            nextHandleFn={this.nextHandleFn.bind(this)}/>
                    </NewIncreased>:                             
                    ''
                }
            </div>
        )
    }
}
export default AddNew